package com.xiashitech.apiservice.service.impl;

import com.google.auto.service.AutoService;
import com.xiashitech.apiservice.Constants.EnAndDecryption;
import com.xiashitech.apiservice.service.IEnAndDecryption;
import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;

@AutoService(IEnAndDecryption.class)
public class EnAndDecryptionImpl implements IEnAndDecryption {
    @Override
    public String cryptionType() {
        return EnAndDecryption.SIGNTYPE_MD5;
    }

    @Override
    public Boolean verifySign(String sign, String sourceKeys) {
        Boolean verifyPass;
        try {
            String sourceSign = DigestUtils.md5DigestAsHex(sourceKeys.getBytes("utf-8"));
            if(sign.equals(sourceSign)) {
                verifyPass = true;
            } else {
                verifyPass = false;
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return verifyPass;
    }
}
